/*
 * Level.h
 *
 */

#ifndef LEVEL_H_
#define LEVEL_H_

#include "Matrix.h"
#include "Model3D.h"
#include "Vertex.h"

#include <vector>
#include <iostream>
#include <gl/gl.h>

#define NO_BOX 0
#define LEVEL_BOX 1
#define BREAK_BOX 2

#include <cmath>

struct Location
{
	float x, y, z;
	std::vector <Face> *geometry;
	std::vector <Face> *v_geometry;

	std::vector <Vertex> *box_Vertices;
	std::vector <Vertex> *box_Normals;
	std::vector <Vertex2D> *box_Texcoord;

	int box;
	bool isOnFire;

	float timeout;
	bool blowing_up;

	Model3D *model3d[3]; // pointer for a bomb and 2 players

	int bonus_type;		// bonus id: 0-no bonus, 1-extra bomb, 2-increase flame, ...

	bool addModel3dPointer(Model3D *model3d){
		for(int i=0; i<3; i++){
			if(this->model3d[i] == NULL){
				this->model3d[i] = model3d;
				return true;
			}
		}
		return false;
	}

	bool removeModel3dPointer(Model3D *model3d){
		for(int i=0; i<3; i++){
			if(this->model3d[i] == model3d){
				this->model3d[i] = NULL;
				return true;
			}
		}
		return false;
	}
};

class Level {
public:
	Level(int cols, int rows);
	virtual ~Level();

	void render3D();
	void move(Vertex &pos, Vertex &dest, float r, float milis);
	void heightCorrection(Vertex &pos);
	void initializeGL();
	void addGeometry(int x, int y, Vertex pos, float r);
	void removeGeometry(int x, int y);
	void destroyBox(int x, int y);
	void generateBonus(int &bonus_type);
	void processBonus(int bonus_type);
	void update(float milis);

	int cols, rows;
	Matrix <Location> model;

	/* Structures for fast drawing */
	std::vector <Vertex> m_Vertices;
	std::vector <Vertex> m_Normals;
	std::vector <Vertex2D> m_Texcoord;

private:
	GLuint *texture;

	float levelGenFunc(float x, float y);
};

#endif /* LEVEL_H_ */
